<?php
//Percorso dove raccoglieremo gli allegati

//Nome e Cognome
date_default_timezone_set('Europe/Rome');
$nome = $_POST['nome'];
$indirizzo = $_POST['indirizzo'];
$numerotel = $_POST['numerotel'];
$email = $_POST['email'];
$today = getdate();
$data = print_r($today);

if ((($_FILES["uploadedfile"]["type"] == "image/gif")
|| ($_FILES["uploadedfile"]["type"] == "image/jpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/pjpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/png")
|| ($_FILES["uploadedfile"]["type"] == "application/octet-stream")
|| ($_FILES["uploadedfile"]["type"] == "application/x-zip-compressed"))
&& ($_FILES["uploadedfile"]["size"] < 2000000))
{
	if ($_FILES["uploadedfile"]["error"] > 0)
	{
		echo "Return Code: " . $_FILES["uploadedfile"]["error"] . "<br />";
	}
	else
	{
		echo "Upload: " . $_FILES["uploadedfile"]["name"] . "<br />";
		echo "Type: " . $_FILES["uploadedfile"]["type"] . "<br />";
		echo "Size: " . ($_FILES["uploadedfile"]["size"] / 1024) . " Kb<br />";
		echo "Temp file: " . $_FILES["uploadedfile"]["tmp_name"] . "<br />";

		if (file_exists("upload/" . $_FILES["uploadedfile"]["name"]))
		{
			echo $_FILES["uploadedfile"]["name"] . " already exists. ";
		}
		else
		{
			move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],
      "upload/" . $_FILES["uploadedfile"]["name"]);
			echo "Stored in: " . "upload/" . $_FILES["uploadedfile"]["name"];
		}
	}
}
else
{
	echo "Invalid file";
}


//Upload dell'allegato
//Messaggio
$oggetto = "Richiesta Preventivo Impianto Fotovoltaico";
$messaggio = "&Egrave; stata ricevuta la seguente richiesta di preventivo per Impianti Fotovoltaici:<br><br>
<b>Dati anagrafici</b> <br/>
Nome: $nome\n<br>
Indirizzo: $indirizzo\n<br>
Numero Telefono: $numerotel\n<br>
Indirizzo email a cui inviare il prevenitvo: $email\n<br>";
//Inclusione della libreria
require_once("class.phpmailer.php");
//Creiamo un oggetto PHPMailer e ne settiamo le variabili

$mail = new PHPMailer();

$mail->IsQMAIL();
$mail->Host = 'smtp.greencubestudio.it';
$mail->Port =587;
$mail->From = 'info@greencubestudio.it';
$mail->Paswword = 'infoprovv';
$mail->FromName = $nome;


$mail->AddAddress("jozmile@gmail.com");
$mail->IsHTML(true);
$mail->Subject = $oggetto;
$mail->Body = $messaggio;
$mail->AddAttachment("upload/".$_FILES["uploadedfile"]["name"]);


//$mail->AddAttachment($_FILES['allegato']['tmp_name'],$_FILES['allegato']['name']);
//Inviamo l'email
if(!$mail->Send())
{
	echo "Message was not sent<p>";
	echo "Mailer Error: " . $mail->ErrorInfo;
	exit;
}

// echo "Upload: " . $_FILES["uploadedfile"]["name"] . "<br />";
// echo "Type: " . $_FILES["uploadedfile"]["type"] . "<br />";
// echo "Size: " . ($_FILES["uploadedfile"]["size"] / 1024) . " Kb<br />";
// echo "Temp file: " . $_FILES["uploadedfile"]["tmp_name"] . "<br />";
// echo "Message sent. Stored in: " . "upload/" . $_FILES["uploadedfile"]["name"];
header('Location: /?page=14');
?>
